import Vue from 'vue';
import VueRouter from 'vue-router';

import Home from '../views/Home.vue';

import Classify from '../views/Classify.vue';

import Flowerchip from '../views/Flowerchip.vue';
Vue.use(VueRouter);

const router = new VueRouter({
  routes: [
    {
      path: '/',
      name: 'Home',
      component: () =>
        import(/* webpackChunkame: "about" */ '../views/Home.vue'),
      meta: {
        isShow: true,
      },
    },
    {
      path: '/home',
      name: 'Home',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Home.vue'),
      meta: {
        isShow: true,
      },
    },
    {
      path: '/pay',
      name: 'Pay',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Pay.vue'),
    },
    {
      path: '/classify',
      name: 'Classify',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Classify.vue'),
      meta: {
        isShow: true,
      },
    },
    {
      path: '/flowerchip',
      name: 'Flowerchip',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Flowerchip.vue'),
      meta: {
        isShow: true,
      },
    },
    {
      path: '/mine',
      name: 'Mine',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Mine.vue'),
      meta: {
        isShow: true,
      },
    },
    {
      path: '/cart',
      name: 'Cart',
      // route level code-splitting
      //
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Cart.vue'),
      meta: {
        isShow: true,
        isLogin: true,
      },
    },
    {
      path: '/submit',
      name: 'SubmitOrder',
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/SubmitOrder.vue'),
      meta: {
        isShow: false,
      },
    },
    {
      path: '/submit/orderuser',
      name: 'OrderUser',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/OrderUser.vue'),
      meta: {
        isShow: false,
        isLogin: true,
      },
    },
    {
      path: '/allorder',
      name: 'Allorder',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Allorder.vue'),
      meta: {
        isShow: false,
        isLogin: true,
      },
    },
    {
      path: '/submit/message',
      name: 'Message',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Message.vue'),
      meta: {
        isShow: false,
      },
    },
    {
      path: '/prolist',
      name: 'ProductList',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/ProductList.vue'),
      meta: {
        isShow: false,
      },
    },
    // import( /* webpackChunkName: "about" */ '../views/Classlist.vue'),
    {
      path: '/classlist/:class',
      name: 'ClassList',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Classlist.vue'),
      meta: {
        isShow: false,
      },
    },
    {
      path: '/prolist/desc/:id',
      name: 'Desc',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Desc.vue'),
    },
    {
      path: '/kefu',
      name: 'Kefu',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Kefu.vue'),
      meta: {
        isShow: false,
      },
    },
    {
      path: '/login',
      name: 'Login',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Login.vue'),
      meta: {
        isShow: false,
      },
    },
    {
      path: '/register',
      name: 'Register',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Register.vue'),
      meta: {
        isShow: false,
      },
    },
    {
      path: '/service',
      name: 'Service',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Service.vue'),
    },
    {
      path: '/delivery',
      name: 'Delivery',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Delivery.vue'),
    },
    {
      path: '/xinjian',
      name: 'Xinjian',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Xinjian.vue'),
    },
    {
      path: '/shanchudizhi',
      name: 'Shanchudizhi',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Shanchudizhi.vue'),
    },
    {
      path: '/alldelivery',
      name: 'AllDelivery',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/AllDelivery.vue'),
    },

    {
      path: '/help',
      name: 'Helpcenter',
      component: () =>
        import(
          /* webpackChunkName: "about" */
          '../views/helpcenter.vue'
        ),
    },
    {
      path: '/chat',
      name: 'Servicemain',
      component: () =>
        import(
          /* webpackChunkName: "about" */
          '../../src/components/chat/chatmain.vue'
        ),
    },
    {
      path: '/search',
      name: 'Search',
      component: () =>
        import(/* webpackChunkName: "about" */ '../components/About/search'),
    },
    {
      path: '/per',
      name: 'Personal',
      component: () =>
        import(/* webpackChunkName: "about" */ '../views/Personal.vue'),
    },
  ],
});

function needLogin() {
  if (localStorage.getItem('token')) {
    return true;
  }
  return false;
}
router.beforeEach((to, from, next) => {
  if (to.meta.isLogin) {
    if (needLogin()) {
      next();
    } else {
      next({ name: 'Login' });
    }
  } else {
    next();
  }
});
export default router;
